/*
 * if one provider can't handle an event for the entire tour party but multiple
 * providers have sufficient total availability, (e.g., restaurants or hotels),
 * split the group among several providers for that event.
 */
public class SchedulerC implements Scheduler
{
    private String message;
    
    @Override
    public boolean schedule(TourOffering offering)
    {// initially just check that tour isn't over-filled
        if (offering.getNumReservations() <= offering.getTour().getMaxSize())
        {
            int eventCapacity;
            
            // check events' provider + aux providers have enough room
            for (Event e : offering.getTour().getEvents())
            {
                eventCapacity = 0;
                
                // go through all providers and find total capacity
                for (Provider p : e.getProviders())
                {
                    eventCapacity += p.getCapacity();
                }
                
                // is there enough room for everyone in the event?
                if (e.getProvider() != null && ((e.getEventType() == EventType.LODGING && eventCapacity < offering.getRoomsRequired())
                        || (e.getEventType() != EventType.LODGING && eventCapacity < offering.getTour().getMaxSize())))
                {
                    message = e.getEventType() + " event over capacity even with multiple providers, placing tour on hold pending cancellations.";
                    return false;
                }
            }
            
            message = "Events have sufficient capacity with multiple providers.";
            return true;
        }
        else
        {
            message = "Tour over capacity";
            return false;
        }
    }
    
    @Override
    public String getMessage()
    {
        return "Level C: " + message;
    }
}
